home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / mesa / mesa-glut / src-glut.aos / glutinit.c < prev    next >
C/C++ Source or Header  |  2000-02-23  |  6KB  |  215 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  1.1
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * glutInit.c
  23.  *
  24.  * Version 1.0  27 Jun 1998
  25.  * by Jarno van der Linden
  26.  * jarno@kcbbs.gen.nz
  27.  *
  28.  * Version 1.1  02 Aug 1998
  29.  * by Jarno van der Linden
  30.  * jarno@kcbbs.gen.nz
  31.  *
  32.  * - Added quantizer plugin arguments
  33.  *
  34.  */
  35.  
  36. #include <string.h>
  37. #include <inline/intuition.h>
  38. #include <intuition/screens.h>
  39. #include "glutstuff.h"
  40.  
  41. int Limit(int v, int minv, int maxv)
  42. {
  43.   if (v < minv)
  44.     return (minv);
  45.   if (v > maxv)
  46.     return (maxv);
  47.  
  48.   return (v);
  49. }
  50.  
  51. void RemoveArg(int n, int *argc, char **argv)
  52. {
  53.   int t;
  54.   char *p;
  55.  
  56.   p = argv[n];
  57.  
  58.   for (t = n; t < ((*argc) - 1); t++) {
  59.     argv[t] = argv[t + 1];
  60.   }
  61.   argv[(*argc) - 1] = p;
  62.   (*argc)--;
  63. }
  64.  
  65. void glutInit(int *argcp, char **argv)
  66. {
  67.   int t;
  68.   char *geometrystring = 0;
  69.   struct Screen *screen;
  70.  
  71.   CurrentTime(&(glutstuff.basetime_secs), &(glutstuff.basetime_micros));
  72.   glutstuff.havebasetime = TRUE;
  73.  
  74.   for (t = (*argcp) - 1; t >= 1; t--) {
  75.     if (!stricmp(argv[t], "-pubscreen")) {
  76.       if (t < ((*argcp) - 1)) {
  77.     glutstuff.pubscreenname = argv[t + 1];
  78.     RemoveArg(t, argcp, argv);
  79.     RemoveArg(t, argcp, argv);
  80.       }
  81.     }
  82.     else if (!strcmp(argv[t], "-display")) {
  83.       DEBUGOUT(1, "%s option invalid for amigaos glut.\n", argv[t]);
  84.       if (t < ((*argcp) - 1))
  85.     RemoveArg(t, argcp, argv);
  86.       RemoveArg(t, argcp, argv);
  87.     }
  88.     else if (!strcmp(argv[t], "-direct") ||
  89.          !strcmp(argv[t], "-indirect") ||
  90.          !strcmp(argv[t], "-sync")) {
  91.       DEBUGOUT(1, "%s option invalid for amigaos glut.\n", argv[t]);
  92.       RemoveArg(t, argcp, argv);
  93.     }
  94.     else if (!strcmp(argv[t], "-iconic") ||
  95.          !strcmp(argv[t], "-gldebug")) {
  96.       RemoveArg(t, argcp, argv);
  97.     }
  98.     else if (!strcmp(argv[t], "-geometry")) {
  99.       if (t < ((*argcp) - 1) && argv[t + 1][0]) {
  100.     geometrystring = argv[t + 1];
  101.     RemoveArg(t, argcp, argv);
  102.       }
  103.       RemoveArg(t, argcp, argv);
  104.     }
  105.     else if (!stricmp(argv[t], "-double")) {
  106.       if (t < ((*argcp) - 1)) {
  107.     if (!stricmp(argv[t + 1], "on"))
  108.       glutstuff.doublemode = 1;
  109.     else if (!stricmp(argv[t + 1], "off"))
  110.       glutstuff.doublemode = -1;
  111.     RemoveArg(t, argcp, argv);
  112.       }
  113.       RemoveArg(t, argcp, argv);
  114.     }
  115.     else if (!stricmp(argv[t], "-rgba")) {
  116.       if (t < ((*argcp) - 1)) {
  117.     if (!stricmp(argv[t + 1], "on"))
  118.       glutstuff.rgbamode = 1;
  119.     else if (!stricmp(argv[t + 1], "off"))
  120.       glutstuff.rgbamode = -1;
  121.     RemoveArg(t, argcp, argv);
  122.       }
  123.       RemoveArg(t, argcp, argv);
  124.     }
  125.     else if (!stricmp(argv[t], "-stereo")) {
  126.       if (t < ((*argcp) - 1)) {
  127.     if (!stricmp(argv[t + 1], "on"))
  128.       glutstuff.stereomode = 1;
  129.     else if (!stricmp(argv[t + 1], "off"))
  130.       glutstuff.stereomode = -1;
  131.     RemoveArg(t, argcp, argv);
  132.       }
  133.       RemoveArg(t, argcp, argv);
  134.     }
  135.     else if (!stricmp(argv[t], "-palmode")) {
  136.       if (t < ((*argcp) - 1)) {
  137.     if (!stricmp(argv[t + 1], "weighted"))
  138.       glutstuff.palmode = AMESA_WEIGHTED_MATCH;
  139.     else if (!stricmp(argv[t + 1], "colorshift"))
  140.       glutstuff.palmode = AMESA_TRUECOLOR_SHIFT;
  141.     else if (!stricmp(argv[t + 1], "colormatch"))
  142.       glutstuff.palmode = AMESA_TRUECOLOR_MATCH;
  143.     else if (!stricmp(argv[t + 1], "grey"))
  144.       glutstuff.palmode = AMESA_GREY_MATCH;
  145.     else if (!stricmp(argv[t + 1], "hpcr"))
  146.       glutstuff.palmode = AMESA_HPCR_MATCH;
  147.     RemoveArg(t, argcp, argv);
  148.       }
  149.       RemoveArg(t, argcp, argv);
  150.     }
  151.   }
  152.  
  153.   if (!(screen = LockPubScreen(glutstuff.pubscreenname)))
  154.     screen = LockPubScreen(NULL);
  155.   if (screen) {
  156.     glutstuff.scrwidth = screen->Width;
  157.     glutstuff.scrheight = screen->Height;
  158.     DEBUGOUT(2, "screen dimensions are %dx%d\n", glutstuff.scrwidth, glutstuff.scrheight);
  159.     UnlockPubScreen(NULL, screen);
  160.   }
  161.  
  162.   if (geometrystring) {
  163.     unsigned char *string = geometrystring, *nextstring;
  164.  
  165.     if ((nextstring = strchr(string, 'x')) || (nextstring = strchr(string, 'X'))) {
  166.       *nextstring++ = 0;
  167.       glutstuff.initwidth = atoi(string);
  168.       DEBUGOUT(2, "geometry initwidth is %s (%d)\n", string, glutstuff.initwidth);
  169.       string = nextstring;
  170.     }
  171.  
  172.     if (!((*string == '-') || (*string == '+'))) {
  173.       char removed;
  174.  
  175.       nextstring = string;
  176.       while (!((*nextstring == '-') || (*nextstring == '+') || (*nextstring == '\0')))
  177.     nextstring++;
  178.       removed = *nextstring;
  179.       *nextstring = 0;
  180.       glutstuff.initheight = atoi(string);
  181.       DEBUGOUT(2, "geometry initheight is %s (%d)\n", string, glutstuff.initheight);
  182.       *nextstring = removed;
  183.       string = nextstring;
  184.     }
  185.  
  186.     if (((*string == '-') || (*string == '+'))) {
  187.       char removed;
  188.  
  189.       nextstring = string + 1;
  190.       while (!((*nextstring == '-') || (*nextstring == '+') || (*nextstring == '\0')))
  191.     nextstring++;
  192.       removed = *nextstring;
  193.       *nextstring = 0;
  194.       glutstuff.initposx = glutstuff.scrwidth - glutstuff.initwidth + atoi(string);
  195.       DEBUGOUT(2, "geometry initposx is %s (%d)\n", string, glutstuff.initposx);
  196.       *nextstring = removed;
  197.       string = nextstring;
  198.     }
  199.  
  200.     if (((*string == '-') || (*string == '+'))) {
  201.       char removed;
  202.  
  203.       nextstring = string + 1;
  204.       while (!((*nextstring == '-') || (*nextstring == '+') || (*nextstring == '\0')))
  205.     nextstring++;
  206.       removed = *nextstring;
  207.       *nextstring = 0;
  208.       glutstuff.initposy = glutstuff.scrheight - glutstuff.initheight + atoi(string);
  209.       DEBUGOUT(2, "geometry initposy is %s (%d)\n", string, glutstuff.initposy);
  210.       *nextstring = removed;
  211.       string = nextstring;
  212.     }
  213.   }
  214. }
  215.